package com.wx.mall.sys.controller;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wx.mall.common.api.CommonPage;
import com.wx.mall.common.api.CommonResult;
import com.wx.mall.common.exceptions.ApiAssert;
import com.wx.mall.common.utils.DataResult;
import com.wx.mall.sys.entity.PayConfig;
import com.wx.mall.sys.service.IPayConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 支付设置 前端控制器
 * </p>
 *
 * @author j
 * @since 2020-03-27
 */
@RestController
@RequestMapping("/payConfig")
@Api(tags = "支付设置相关接口")
public class PayConfigController {

    @Autowired
    private IPayConfigService payConfigService;

    @GetMapping("/payConfigs")
    @ApiOperation("查询接口")
    public CommonResult findAll() {
        List<PayConfig> list = payConfigService.list();
        return CommonResult.success(list);
    }

    @GetMapping("/payConfig/{id}")
    @ApiOperation("根据id查询接口")
    public CommonResult findById(@PathVariable("id") @NotNull(message = "id不能为空") Integer id) {
        PayConfig byId = payConfigService.getById(id);
        return CommonResult.success(byId);
    }

    @PutMapping("/payConfig")
    @ApiOperation("编辑接口")
    public CommonResult updateById(PayConfig payConfig) {
        boolean b = payConfigService.updateById(payConfig);
        if (!b) {
            ApiAssert.fail("修改失败");
        }
        return CommonResult.success();
    }
}

